'''
    test-01.py
    author: yizimi-yuanxin 
    update: 3.17
    
    status: operational
    [yizimi 3.17] for mysql in database sec_test in IP: 192.168.1.133 in virtual linux: ubuntu-server 
    need to set mysql /etc/mysql/my.cnf : [mysqld] \n \n bind-address = 0.0.0.0
'''

#!/usr/bin/python3
# from sshtunnel import SSHTunnelForwarder
import  pymysql

# 打开数据库连接
db = pymysql.connect(host="192.168.1.133", user="yizimi", password="yizimi5253", database="sec_test", port=3306, charset='utf8')
# yizimi's WSL IP
# db = pymysql.connect(host="172.20.35.19", user="yizimi", passwd="Litianhao-5253", database="sec_test", port=3306, charset='utf8') 

# 使用 cursor() 方法创建一个游标对象
cursor = db.cursor()

# 使用 execute()  方法执行 SQL 查询 
cursor.execute("SELECT VERSION()")

# 使用 fetchone() 方法获取单条数据.
data = cursor.fetchone()

print("Database version : %s " % data)# 关闭数据库连接

db.close()
